package com.neu.controller;

import com.neu.constant.ResultCodeEnum;
import com.neu.mapper.EventMapper;
import com.neu.pojo.Event;
import com.neu.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping(value = "/event", produces = {"application/json;charset=UTF-8"})
public class EventController {

    @Resource
    private EventMapper eventMapper;

    @GetMapping("/list")
    public Object list() {
        log.info("查询公司事迹");
        return eventMapper.listEvent();
    }
    @PostMapping("/i")
    public Object add(@RequestBody Event event) {
        log.info("新增公司事迹:{}", event);
        return eventMapper.insertEvent(event);
    }

    @PostMapping("/w")
    public Object update(@RequestBody Event event) {
        log.info("修改公司事迹信息:{}", event);
        return eventMapper.updateEvent(event);
    }

    @PostMapping("/d")
    public Object del(Integer id) {
        log.info("删除公司事迹:{}", id);
        if (id <= 0) {
            return Result.error(ResultCodeEnum.PARAM_CHECK_ERROR);
        }
        return eventMapper.deleteEvent(id);
    }
}
